package top.andoudou.generator.mybatis.runer;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import top.andoudou.generator.mybatis.config.CodeProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class GenCodeRunner implements CommandLineRunner {
    @Autowired
    CodeProperties properties;

    /**
     * 生成代码
     * @param strings
     * @throws Exception
     */
    @Override
    public void run(String... strings) throws Exception {

        AutoGenerator autoGenerator = new AutoGenerator();

        autoGenerator.setGlobalConfig(properties.getGlobal());
        autoGenerator.setCfg(properties.getInjectionConfig());
        autoGenerator.setDataSource(properties.getDataSource());
        autoGenerator.setPackageInfo(properties.getPackages());
        autoGenerator.setStrategy(properties.getStrategy());
        autoGenerator.setTemplate(properties.getTemplate());

        autoGenerator.execute();

    }
}

